{smcl}
{com}{sf}{ul off}{txt}{.-}
      name:  {res}<unnamed>
       {txt}log:  {res}C:\Users\myogo\Princeton Dropbox\Motohiro Yogo\Koijen Yogo - International\JPE\Replication\Code\1 Data\Datastream.smcl
  {txt}log type:  {res}smcl
 {txt}opened on:  {res} 7 Nov 2025, 15:00:44
{txt}
{com}. /* Define local and global variables */
> 
> local directory = "../../Data/Datastream";
{txt}
{com}. local directory_nonpublic = "../../Data_nonpublic/Datastream";
{txt}
{com}. do global;
{txt}
{com}. /* global.do (STATA)
>         Define global variables in "Data".
>         by Ralph Koijen & Motohiro Yogo */
. 
. #delimit ;
{txt}delimiter now ;
{com}. clear all;
{res}{txt}
{com}. global year_min = 2003;
{txt}
{com}. global year_max = 2020;
{txt}
{com}. global small = 5e-4;
{txt}
{com}.         /* Minimum reportable threshold for CPIS */

{txt}end of do-file

{com}. /* Step 1: Construct MSCI returns */
> 
> /* Load country names */
> 
> import excel using "`directory_nonpublic'/MSCI.xlsm",
>         sheet("Legend") first clear;
{res}{text}(5 vars, 49 obs)

{com}. /* Fix variables */
> 
> replace CodeUS = subinstr(CodeUS,"$(RI)","RI",1);
{txt}(49 real changes made)

{com}. replace CodeLC = subinstr(CodeLC,"(RI)","RI",1);
{txt}(49 real changes made)

{com}. /* Save data */
> 
> tempfile Legend;
{txt}
{com}. save `Legend';
{txt}{p 0 4 2}
file {bf}
C:\Users\myogo\AppData\Local\Temp\ST_8970_000001.tmp{rm}
saved
as .dta format
{p_end}

{com}. /* Load world returns */
> 
> import excel using "`directory_nonpublic'/MSCI.xlsm",
>         sheet("World Return US") cellra(A2) first clear;
{res}{text}(3 vars, 625 obs)

{com}. /* Rename variables */
> 
> rename Code Date;
{res}{txt}
{com}. /* Construct returns */
> 
> sort Date;
{txt}
{com}. gen retMSWRLDRI = ln(MSWRLDRI/MSWRLDRI[_n-1]);
{txt}(1 missing value generated)

{com}. drop MS*;
{txt}
{com}. /* Save data */
> 
> tempfile WorldReturn;
{txt}
{com}. save `WorldReturn';
{txt}{p 0 4 2}
file {bf}
C:\Users\myogo\AppData\Local\Temp\ST_8970_000002.tmp{rm}
saved
as .dta format
{p_end}

{com}. /* Load returns in US$ */
> 
> import excel using "`directory_nonpublic'/MSCI.xlsm",
>         sheet("Total Return US") cellra(A2) first clear;
{res}{text}(50 vars, 625 obs)

{com}. /* Rename variables */
> 
> rename Code Date;
{res}{txt}
{com}. foreach var of varlist MS* {c -(};
{txt}  2{com}.         rename `var' MS`var';
{txt}  3{com}. {c )-};
{res}{txt}
{com}. /* Reshape in long format */
> 
> reshape long MS, i(Date) j(CodeUS) string;
{txt}(j = MSARGTRI MSASTRRI MSAUSTRI MSBELGRI MSBRAZRI MSCHILRI MSCHINRI MSCNDARI MSCOLMRI MSCZCHRI MSDNMKRI MSEGYTRI MSEIRERI MSFINDRI MSFRNCRI MSGERMRI MSGREERI MSHGKGRI MSHUNGRI MSINDFRI MSINDIRI MSISRLRI MSITALRI MSJORDRI MSJPANRI MSKORERI MSMALFRI MSMEXFRI MSMORCRI MSNETHRI MSNWAYRI MSNZEARI MSPAKIRI MSPERURI MSPHLFRI MSPLNDRI MSPORDRI MSRUSSRI MSSARFRI MSSINGRI MSSPANRI MSSRILRI MSSWDNRI MSSWITRI MSTAIWRI MSTHAFRI MSTURKRI MSUSAMRI MSUTDKRI)

Data{col 36}Wide{col 43}->{col 48}Long
{hline 77}
Number of observations     {res}         625   {txt}->   {res}30,625      
{txt}Number of variables        {res}          50   {txt}->   {res}3           
{txt}j variable (49 values)                    ->   {res}CodeUS
{txt}xij variables:
   {res}MSMSARGTRI MSMSASTRRI ... MSMSUTDKRI   {txt}->   {res}MS
{txt}{hline 77}

{com}. /* Merge country names */
> 
> merge m:1 CodeUS using `Legend',
>         keepusing(Name)
>         nogen;
{res}{txt}{p 0 7 2}
(variable
{bf:CodeUS} was {bf:str8}, now {bf:str11} to accommodate using data's values)
{p_end}

{col 5}Result{col 33}Number of obs
{col 5}{hline 41}
{col 5}Not matched{col 30}{res}               0
{txt}{col 5}Matched{col 30}{res}          30,625{txt}  
{col 5}{hline 41}

{com}. drop CodeUS;
{txt}
{com}. /* Save data */
> 
> tempfile ReturnUS;
{txt}
{com}. save `ReturnUS';
{txt}{p 0 4 2}
file {bf}
C:\Users\myogo\AppData\Local\Temp\ST_8970_000003.tmp{rm}
saved
as .dta format
{p_end}

{com}. /* Load returns in local currency */
> 
> import excel using "`directory_nonpublic'/MSCI.xlsm",
>         sheet("Total Return LC") cellra(A2) first clear;
{res}{text}(50 vars, 625 obs)

{com}. /* Rename variables */
> 
> rename Code Date;
{res}{txt}
{com}. foreach var of varlist MS* {c -(};
{txt}  2{com}.         rename `var' MSL`var';
{txt}  3{com}. {c )-};
{res}{txt}
{com}. /* Reshape in long format */
> 
> reshape long MSL, i(Date) j(CodeLC) string;
{txt}(j = MSARGTLRI MSASTRLRI MSAUSTLRI MSBELGLRI MSBRAZLRI MSCHILLRI MSCHINLRI MSCNDALRI MSCOLMLRI MSCZCHLRI MSDNMKLRI MSEGYTLRI MSEIRELRI MSFINDLRI MSFRNCLRI MSGERMLRI MSGREELRI MSHGKGLRI MSHUNGLRI MSINDFLRI MSINDILRI MSISRLLRI MSITALLRI MSJORDLRI MSJPANLRI MSKORELRI MSMALFLRI MSMEXFLRI MSMORCLRI MSNETHLRI MSNWAYLRI MSNZEALRI MSPAKILRI MSPERULRI MSPHLFLRI MSPLNDLRI MSPORDLRI MSRUSSLRI MSSARFLRI MSSINGLRI MSSPANLRI MSSRILLRI MSSWDNLRI MSSWITLRI MSTAIWLRI MSTHAFLRI MSTURKLRI MSUSAMLRI MSUTDKLRI)

Data{col 36}Wide{col 43}->{col 48}Long
{hline 77}
Number of observations     {res}         625   {txt}->   {res}30,625      
{txt}Number of variables        {res}          50   {txt}->   {res}3           
{txt}j variable (49 values)                    ->   {res}CodeLC
{txt}xij variables:
{res}MSLMSARGTLRI MSLMSASTRLRI ... MSLMSUTDKLRI{txt}->   {res}MSL
{txt}{hline 77}

{com}. /* Merge country names */
> 
> merge m:1 CodeLC using `Legend',
>         keepusing(Name)
>         nogen;
{res}{txt}{p 0 7 2}
(variable
{bf:CodeLC} was {bf:str9}, now {bf:str11} to accommodate using data's values)
{p_end}

{col 5}Result{col 33}Number of obs
{col 5}{hline 41}
{col 5}Not matched{col 30}{res}               0
{txt}{col 5}Matched{col 30}{res}          30,625{txt}  
{col 5}{hline 41}

{com}. drop CodeLC;
{txt}
{com}. /* Merge world returns */
> 
> merge m:1 Date using `WorldReturn',
>         nogen;
{res}
{txt}{col 5}Result{col 33}Number of obs
{col 5}{hline 41}
{col 5}Not matched{col 30}{res}               0
{txt}{col 5}Matched{col 30}{res}          30,625{txt}  
{col 5}{hline 41}

{com}. /* Merge returns in US$ */
> 
> merge 1:1 Date Name using `ReturnUS',
>         nogen;
{res}
{txt}{col 5}Result{col 33}Number of obs
{col 5}{hline 41}
{col 5}Not matched{col 30}{res}               0
{txt}{col 5}Matched{col 30}{res}          30,625{txt}  
{col 5}{hline 41}

{com}. /* Construct variables */
> 
> gen int year = year(Date);
{txt}(49 missing values generated)

{com}. replace Date = mofd(Date);
{txt}(30,576 real changes made)

{com}. /* Construct returns */
> 
> sort Name Date;
{txt}
{com}. foreach var of varlist MS MSL {c -(};
{txt}  2{com}.         by Name: gen ret`var' = ln(`var'/`var'[_n-1]);
{txt}  3{com}. {c )-};
{txt}(7,705 missing values generated)
(7,705 missing values generated)

{com}. drop MS*;
{txt}
{com}. /* Construct beta and volatility */
> 
> gen beta = .;
{txt}(30,625 missing values generated)

{com}. gen vol = .;
{txt}(30,625 missing values generated)

{com}. qui forval d = `=tm(${c -(}year_min{c )-}m12)'(12)`=tm(${c -(}year_max{c )-}m12)' {c -(};
{txt}
{com}. drop retMSWRLDRI;
{txt}
{com}. /* Construct annual returns */
> 
> foreach var of varlist retMS retMSL {c -(};
{txt}  2{com}.         egen ret = total(`var'), missing by(year Name);
{txt}  3{com}.         replace `var' = ret;
{txt}  4{com}.         drop ret;
{txt}  5{com}. {c )-};
{txt}(7,687 missing values generated)
(22,920 real changes made)
(7,687 missing values generated)
(22,920 real changes made)

{com}. /* Keep month end */
> 
> keep if month(dofm(Date))==12;
{txt}(28,077 observations deleted)

{com}. drop Date;
{txt}
{com}. /* Save data */
> 
> tempfile Return;
{txt}
{com}. save `Return';
{txt}{p 0 4 2}
file {bf}
C:\Users\myogo\AppData\Local\Temp\ST_8970_000004.tmp{rm}
saved
as .dta format
{p_end}

{com}. /* Step 2: Construct interest rates */
> 
> /* Load country names */
> 
> import excel using "`directory'/Interest Rates.xlsm",
>         sheet("Legend") first clear;
{res}{text}(5 vars, 50 obs)

{com}. /* Fix variables */
> 
> replace Code3M = subinstr(Code3M,".","",.);
{txt}(2 real changes made)

{com}. /* Save data */
> 
> tempfile Legend;
{txt}
{com}. save `Legend';
{txt}{p 0 4 2}
file {bf}
C:\Users\myogo\AppData\Local\Temp\ST_8970_000005.tmp{rm}
saved
as .dta format
{p_end}

{com}. /* Load 10-year benchmark government yields */
> 
> import excel using "`directory'/Interest Rates.xlsm",
>         sheet("10Y Government") cellra(A2) first clear;
{res}{text}(50 vars, 505 obs)

{com}. /* Rename variables */
> 
> rename Code Date;
{res}{txt}
{com}. foreach var of varlist TR* {c -(};
{txt}  2{com}.         rename `var' IR10Y`var';
{txt}  3{com}. {c )-};
{res}{txt}
{com}. /* Fix variables */
> 
> replace Date = mofd(Date);
{txt}(505 real changes made)

{com}. /* Reshape in long format */
> 
> reshape long IR10Y, i(Date) j(Code10Y) string;
{txt}(j = TRAR10T TRAU10T TRBD10T TRBG10T TRBR10T TRCH10T TRCL10T TRCN10T TRCO10T TRCZ10T TRDK10T TREG10T TRES10T TRFN10T TRFR10T TRGR10T TRHK10T TRHN10T TRID10T TRIE10T TRIL10T TRIN10T TRIT10T TRJO10T TRJP10T TRKR10T TRLK10T TRMA10T TRMX10T TRMY10T TRNL10T TRNW10T TRNZ10T TROE10T TRPE10T TRPH10T TRPK10T TRPO10T TRPT10T TRRS10T TRSA10T TRSD10T TRSG10T TRSW10T TRTH10T TRTK10T TRTW10T TRUK10T TRUS10T)

Data{col 36}Wide{col 43}->{col 48}Long
{hline 77}
Number of observations     {res}         505   {txt}->   {res}24,745      
{txt}Number of variables        {res}          50   {txt}->   {res}3           
{txt}j variable (49 values)                    ->   {res}Code10Y
{txt}xij variables:
{res}IR10YTRAR10T IR10YTRAU10T ... IR10YTRUS10T{txt}->   {res}IR10Y
{txt}{hline 77}

{com}. /* Merge country names */
> 
> merge m:1 Code10Y using `Legend',
>         keepusing(Name)
>         nogen keep(match);
{res}
{txt}{col 5}Result{col 33}Number of obs
{col 5}{hline 41}
{col 5}Not matched{col 30}{res}               0
{txt}{col 5}Matched{col 30}{res}          24,745{txt}  
{col 5}{hline 41}

{com}. drop Code10Y;
{txt}
{com}. /* Save data */
> 
> tempfile Government;
{txt}
{com}. save `Government';
{txt}{p 0 4 2}
file {bf}
C:\Users\myogo\AppData\Local\Temp\ST_8970_000006.tmp{rm}
saved
as .dta format
{p_end}

{com}. /* Load 3-month interbank rates */
> 
> import excel using "`directory'/Interest Rates.xlsm",
>         sheet("3M Interbank") cellra(A2) first clear;
{res}{text}(40 vars, 505 obs)

{com}. /* Rename variables */
> 
> rename Code Date;
{res}{txt}
{com}. foreach var of varlist AGI60L-ECEUR3M {c -(};
{txt}  2{com}.         rename `var' IR3M`var';
{txt}  3{com}. {c )-};
{res}{txt}
{com}. /* Fix variables */
> 
> replace Date = mofd(Date);
{txt}(505 real changes made)

{com}. /* Reshape in long format */
> 
> reshape long IR3M, i(Date) j(Code3M) string;
{txt}(j = AGI60L BRI60L CAMAD3M CBMIR076R CHIB3MO CLMIR076R CZOIR076R ECASD3M ECAUD3M ECCAD3M ECDKN3M ECEUR3M ECHKD3M ECJAP3M ECNOR3M ECNZD3M ECSAR3M ECSWE3M ECSWF3M ECUKP3M ECUSD3M EGIBK3M HNIBK3M IDMIR076R IN3MDAV ISMIR076R JOIBK3M KOMIR076R MXOIR076R MYIBK3M PEBOR3M PHTBL3M PKIBK3M POOIR076R RSOIR076R SRIBK3M THBBIB3 TKIBK3M TWIBK3M)

Data{col 36}Wide{col 43}->{col 48}Long
{hline 77}
Number of observations     {res}         505   {txt}->   {res}19,695      
{txt}Number of variables        {res}          40   {txt}->   {res}3           
{txt}j variable (39 values)                    ->   {res}Code3M
{txt}xij variables:
  {res}IR3MAGI60L IR3MBRI60L ... IR3MTWIBK3M   {txt}->   {res}IR3M
{txt}{hline 77}

{com}. /* Merge country names */
> 
> merge m:1 Code3M using `Legend',
>         keepusing(Name)
>         nogen keep(match);
{res}{txt}{p 0 7 2}
(variable
{bf:Code3M} was {bf:str9}, now {bf:str11} to accommodate using data's values)
{p_end}

{col 5}Result{col 33}Number of obs
{col 5}{hline 41}
{col 5}Not matched{col 30}{res}               0
{txt}{col 5}Matched{col 30}{res}          19,695{txt}  
{col 5}{hline 41}

{com}. drop Code3M;
{txt}
{com}. /* Merge 10-year benchmark government yields */
> 
> merge 1:1 Date Name using `Government',
>         nogen;
{res}
{txt}{col 5}Result{col 33}Number of obs
{col 5}{hline 41}
{col 5}Not matched{col 30}{res}           6,060
{txt}{col 9}from master{col 30}{res}             505{txt}  
{col 9}from using{col 30}{res}           5,555{txt}  

{col 5}Matched{col 30}{res}          19,190{txt}  
{col 5}{hline 41}

{com}. /* Merge country code */
> 
> merge m:1 Name using Countries,
>         keepusing(country Yeuro)
>         nogen keep(master match);
{res}{txt}{p 0 7 2}
(variable
{bf:Name} was {bf:str14}, now {bf:str32} to accommodate using data's values)
{p_end}

{col 5}Result{col 33}Number of obs
{col 5}{hline 41}
{col 5}Not matched{col 30}{res}             505
{txt}{col 9}from master{col 30}{res}             505{txt}  
{col 9}from using{col 30}{res}               0{txt}  

{col 5}Matched{col 30}{res}          24,745{txt}  
{col 5}{hline 41}

{com}. /* Convert interest rates to decimal */
> 
> foreach var of varlist IR3M IR10Y {c -(};
{txt}  2{com}.         replace `var' = `var'/100;
{txt}  3{com}. {c )-};
{txt}(12,830 real changes made)
(15,218 real changes made)

{com}. /* Construct variables */
> 
> gen int year = year(dofm(Date));
{txt}
{com}. /* Construct dummy for euro area and Denmark */
> 
> gen byte Ieuro = Name=="Euro" | year>=Yeuro | country=="DNK";
{txt}
{com}. drop Yeuro;
{txt}
{com}. /* Common 3-month interbank rate in the euro area */
> 
> sort Date Ieuro country;
{txt}
{com}. by Date Ieuro: replace IR3M = IR3M[1] if Ieuro & Name[1]=="Euro";
{txt}(3443 real changes made, 163 to missing)

{com}. drop if Name=="Euro";
{txt}(505 observations deleted)

{com}. drop Ieuro;
{txt}
{com}. /* Construct dummy for USD countries */
> 
> gen byte Iusd = inlist(country,"USA","HKG");
{txt}
{com}. /* Common 3-month interbank rate for USD countries */
> 
> sort Date Iusd country;
{txt}
{com}. by Date Iusd: replace IR3M = IR3M[_N] if Iusd & country[_N]=="USA";
{txt}(502 real changes made)

{com}. drop Iusd;
{txt}
{com}. /* Construct annual returns */
> 
> gen retIR3M = 0;
{txt}
{com}. sort country Date;
{txt}
{com}. forval i = 3(3)12 {c -(};
{txt}  2{com}.         by country: replace retIR3M = retIR3M+ln(1+IR3M[_n-`i']/4);
{txt}  3{com}. {c )-};
{txt}(24732 real changes made, 9263 to missing)
(15470 real changes made, 177 to missing)
(15293 real changes made, 172 to missing)
(15122 real changes made, 164 to missing)

{com}. /* Keep month end */
> 
> keep if month(dofm(Date))==12;
{txt}(22,638 observations deleted)

{com}. drop Date;
{txt}
{com}. /* Step 3: Merge MSCI returns and interest rates */
> 
> merge 1:1 year Name using `Return',
>         nogen keep(match);
{res}
{txt}{col 5}Result{col 33}Number of obs
{col 5}{hline 41}
{col 5}Not matched{col 30}{res}               0
{txt}{col 5}Matched{col 30}{res}           2,107{txt}  
{col 5}{hline 41}

{com}. drop Name;
{txt}
{com}. /* Sample criteria */
> 
> keep if inrange(year,$year_min,$year_max+1);
{txt}(1,176 observations deleted)

{com}. /* Label variables */
> 
> order year country;
{txt}
{com}. label var year          "year";
{txt}
{com}. label var IR3M          "3-month interbank rate";
{txt}
{com}. label var IR10Y         "10-year benchmark government yield";
{txt}
{com}. label var retIR3M       "Interest rate (LCU, continuously compounded)";
{txt}
{com}. label var retMS         "Stock return (US$, continuously compounded)";
{txt}
{com}. label var retMSL        "Stock return (LCU, continuously compounded)";
{txt}
{com}. label var beta          "Market beta";
{txt}
{com}. label var vol           "Volatility";
{txt}
{com}. /* Save data */
> 
> sort year country;
{txt}
{com}. save Datastream, replace;
{txt}{p 0 4 2}
file {bf}
Datastream.dta{rm}
saved
{p_end}

{com}. log close;
      {txt}name:  {res}<unnamed>
       {txt}log:  {res}C:\Users\myogo\Princeton Dropbox\Motohiro Yogo\Koijen Yogo - International\JPE\Replication\Code\1 Data\Datastream.smcl
  {txt}log type:  {res}smcl
 {txt}closed on:  {res} 7 Nov 2025, 15:00:56
{txt}{.-}
{smcl}
{txt}{sf}{ul off}